// pages/tailorFabric/tailorFabric.js
var app =getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date:'请选择',
    id:'',
    list:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id
    })
    this.getOrder()
  },
  getOrder: function () {
    var that = this
    wx.request({
      url: app.globalData.api + 'productionOrderForm/' + this.data.id,
      data: {},
      header: {
        Authorization: wx.getStorageSync('token')
      },
      success: (res) => {
        console.log(res)
        if (res.data.code == 200) {
          that.setData({
            list: res.data.data
          })
        }
      }
    })
  },
  num:function(e){
    // console.log(e)
    this.data.list.productionItemList[e.currentTarget.dataset.index].accomplishAmount = e.detail.value
  },
  sub:function(){
    if (this.data.date == '请选择'){
      wx.showToast({
        title: '请选择预计发货日期',
      })
      return
    }
    wx.request({
      url: app.globalData.api + 'productionOrderForm/pruneClothing/' + this.data.id,
      data:{
        purchasingOrderFormId: this.data.list.purchasingOrderFormId,
        businessOrderFormId: this.data.list.businessOrderFormId,
        estimatedFinishTime: this.data.date+' 00:00:00',
        productionItemList: this.data.list.productionItemList,
      },
      header:{
        Authorization: wx.getStorageSync('token')
      },
      method:'PUT',
      success:(res)=>{
        console.log(res)
        if(res.data.code == 200){
          wx.showToast({
            title: res.data.msg,
          })
          setTimeout(()=>{
            wx.navigateBack({
              delta: 1
            })
          }, 1000)
        }else{
          wx.showToast({
            icon:'none',
            title: res.data.errorMsg,
          })
        }
      }
    })
  },
  bindDateChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})